package com.ruoyi.project.manage.file.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manage.file.domain.ProjectFile;
import com.ruoyi.project.manage.file.service.IProjectFileService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 项目文件Controller
 * 
 * @author fangkun
 * @date 2022-04-07
 */
@Controller
@RequestMapping("/manage/file")
public class ProjectFileController extends BaseController
{
    private String prefix = "manage/file";

    @Autowired
    private IProjectFileService projectFileService;

    @RequiresPermissions("manage:file:view")
    @GetMapping()
    public String file()
    {
        return prefix + "/file";
    }

    /**
     * 查询项目文件列表
     */
    @RequiresPermissions("manage:file:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectFile projectFile)
    {
        startPage();
        List<ProjectFile> list = projectFileService.selectProjectFileList(projectFile);
        return getDataTable(list);
    }

    /**
     * 导出项目文件列表
     */
    @RequiresPermissions("manage:file:export")
    @Log(title = "项目文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectFile projectFile)
    {
        List<ProjectFile> list = projectFileService.selectProjectFileList(projectFile);
        ExcelUtil<ProjectFile> util = new ExcelUtil<ProjectFile>(ProjectFile.class);
        return util.exportExcel(list, "项目文件数据");
    }

    /**
     * 新增项目文件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目文件
     */
    @RequiresPermissions("manage:file:add")
    @Log(title = "项目文件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectFile projectFile)
    {
        return toAjax(projectFileService.insertProjectFile(projectFile));
    }

    /**
     * 修改项目文件
     */
    @RequiresPermissions("manage:file:edit")
    @GetMapping("/edit/{projectFileId}")
    public String edit(@PathVariable("projectFileId") Long projectFileId, ModelMap mmap)
    {
        ProjectFile projectFile = projectFileService.selectProjectFileByProjectFileId(projectFileId);
        mmap.put("projectFile", projectFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目文件
     */
    @RequiresPermissions("manage:file:edit")
    @Log(title = "项目文件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectFile projectFile)
    {
        return toAjax(projectFileService.updateProjectFile(projectFile));
    }

    /**
     * 删除项目文件
     */
    @RequiresPermissions("manage:file:remove")
    @Log(title = "项目文件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectFileService.deleteProjectFileByProjectFileIds(ids));
    }
}
